package com.edu.controller;

import com.edu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {

    /*
    *       GET请求 在restful 风格中负责做 查询
    * */
    @GetMapping("/user")
    public String showAllUser(){
        System.out.println("查询了所有用户的信息");
        //做查询
        return "/users.jsp";
    }

    @GetMapping("/user/{userId}")
    public String showUserDetail(@PathVariable("userId") String userId){
        System.out.println("查询了id为"+userId+"的用户");
        return "/userDetail.jsp";
    }


    /**
     * 用 Post请求 执行 添加操作
     * @param user
     * @return
     */
    @PostMapping("/user")
    public String addUser(User user){
        System.out.println("执行了 添加用户");
        System.out.println(user);
        return "/users.jsp";
    }


    @DeleteMapping("/user/{userId}")
    public String deleteUser(@PathVariable("userId") int userId){
        System.out.println("删除了 ID为"+userId+"的用户");
        return "redirect:/index.jsp";
    }

    @PutMapping("/user/{userId}")
    public String deleteUser(User user){
        System.out.println(user);
        return "redirect:/index.jsp";
    }

}
